using System;
using Source.Common;


namespace Source.Web.FrameWork
{
    public interface IClientSideUserManager : IUserManager
    {
        Visit GetVisit();
    }

    public class UserManager : IClientSideUserManager
    {
        private readonly IStateProvider stateProvider;
        private const string visitKey = "_userManager_visit";

        public UserManager(IStateProvider stateProvider)
        {
            this.stateProvider = stateProvider;
        }

        public IUser GetCurrentUserInfo()
        {
            var visit = GetVisit();

            return visit != null ? visit.User : null;
        }

        public void StoreCurrentVisitInfo(Visit visit)
        {
            stateProvider.Store(visitKey, visit);
        }

        public Visit GetVisit()
        {
            return stateProvider.Retrieve<Visit>(visitKey);
        }
    }
}